home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13735 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  6.9 KB

  1. Path: news.iadfw.net!usenet
  2. From: jveigel@airmail.net (Jens Veigel)
  3. Newsgroups: comp.lang.c
  4. Subject: Is there an easier way to do this ?
  5. Date: Tue, 09 Apr 1996 01:59:53 GMT
  6. Organization: customer of Internet America
  7. Message-ID: <4kf4r6$sqg@news-f.iadfw.net>
  8. NNTP-Posting-Host: dal03-14.ppp.iadfw.net
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I'm porting an ASPECT (Procomm f win) script to C in Windows and I'm
  12. at the portion where I need to build several list.txt files for my
  13. comboboxes to display filenames longer than 8 characters. The way I do
  14. it in my script is to "cruise" the directories stuff them into an
  15. array and then build the files. My question is: 
  16.  
  17. Is there an easier way to do this than the script below ?
  18. If not I will have to port it to C and add the missing C- language
  19. features like stringinsert and stringextract myself and do it the way
  20. I'm doing it now.  I'm just wondering if I could somehow use some sort
  21. of lookup table or something where I would store my created dir
  22. structure each time a sub dir is created or deleted, instead of having
  23. to run this everytime a new subdir under the "\top & \bot"  has been
  24. created, so I'm current as far as my file combobox text files are
  25. concerned. I reverse the process when a filename of lets say
  26. 69557904031 has been picked from the combobox, I then insert slashes
  27. and build a path like so d:\mpm\line1\top\695\57904031\*.* from which
  28. I transmit files. 
  29.  
  30. Not only takes an array this size a lot of memory but also some time
  31. to "cruise through the dirs to which I add daily 4 or five.
  32. BTW: what's the equivalent to $nullstr in C ? 
  33.  
  34. Any suggestions would be greatly appreciated. 
  35.  
  36. here is how I do it today, again this is not C but aspect but looks
  37. almost like C, except strings are diff in C and of course the array
  38. would be differently acessed ....
  39.  
  40. string  FabArray[10][200][20]
  41. string  linedef, Linedef1t , Linedef1b, Linedef2t, Linedef2b,
  42. Linedef3t, Linedef3b
  43.  
  44. string Filelist
  45. string Listfile
  46.  
  47.  
  48. proc MAIN 
  49.  
  50. Linedef="d:\mpm"
  51. Linedef1t="d:\mpm\line1\top"
  52. Linedef1b="d:\mpm\line1\bot"
  53. Linedef2t="d:\mpm\line2\top"
  54. Linedef2b="d:\mpm\line2\bot"
  55. Linedef3t="d:\mpm\line3\top"
  56. Linedef3b="d:\mpm\line3\bot"
  57.  
  58.  
  59.  
  60. Listfile="Line.txt"
  61.   strcpy Linedef Linedef1t           ;line1\top
  62.   filelist=Linedef
  63. GetList(Linedef)
  64.  
  65. pause 2
  66.   strcpy Linedef Linedef2t             ;line2\top 
  67.   filelist=Linedef
  68. GetList(Linedef)
  69.  
  70. pause 2
  71.   strcpy Linedef Linedef3t              ;line3\top
  72.   filelist=Linedef
  73. GetList(Linedef)
  74.  
  75.  
  76.  
  77. pause 2
  78.   strcpy Linedef Linedef1b            ;line1\bottom
  79.   filelist=Linedef 
  80. GetList(Linedef)
  81.  
  82.  
  83. pause 2
  84.   strcpy Linedef Linedef2b              ;line2\bottom
  85.   filelist=Linedef
  86. GetList(Linedef)
  87.  
  88.  
  89.  
  90. pause 2
  91.   strcpy Linedef LineDef3b            ;line3\bottom
  92.   filelist=Linedef    
  93. GetList(Linedef)
  94.  
  95. endproc
  96.  
  97.  
  98. proc Getlist
  99. param string Leader
  100. integer one, two, three
  101. string line, strvar1, strvar2, strvar3, Level1, Level2, Level3
  102.  
  103. ;clear any old array contents
  104. for one=0 upto 9
  105.         for two=0 upto 199
  106.     for three=0 upto 19
  107.            FabArray[one][two][three]=$nullstr
  108.     endfor
  109.         endfor
  110. endfor            
  111.  
  112. ; get subdirectories in the first level
  113.    one=0
  114.    strvar1=Leader
  115.    addfilename strvar1 "*.*"
  116.    if findfirst strvar1 "D"                        ; findfirst Level1
  117.       Level1=$filename
  118.       strfind Level1 "."
  119.       if failure
  120.          FabArray[one][0][0]=Level1
  121.         strcat Level1 " "
  122.         strupr level1
  123.         usermsg level1
  124.          one++
  125.       endif
  126.       while findnext                               ; findnext Level1
  127.          Level1=$filename        
  128.          if strfind Level1 "."
  129.             loopwhile
  130.          else
  131.             FabArray[one][0][0]=Level1
  132.             one++
  133.          endif
  134.       endwhile
  135.    endif
  136. ; get subdirectories in the second level
  137.    for one=0 upto 29
  138.       two=1
  139.       strvar2=FabArray[one][0][0]
  140.       if strcmp strvar2 $nullstr
  141.          exitfor
  142.       else
  143.          strinsert strvar2 "\" 0
  144.          strinsert strvar2 Leader 0
  145.          addfilename strvar2 "*.*"
  146.       endif
  147.       if findfirst strvar2 "D"                        ; findfirst
  148. Level2
  149.          Level2=$filename
  150.          strfind Level2 "."
  151.          if failure
  152.             strcmp Level2 $nullstr
  153.             if failure
  154.                FabArray[one][two][0]=Level2
  155.                two++
  156.             endif
  157.          endif
  158.          while findnext                               ; findnext
  159. Level2
  160.             Level2=$filename        
  161.             if strfind Level2 "."
  162.                loopwhile
  163.             else
  164.                strcmp Level2 $nullstr
  165.                if failure
  166.                   FabArray[one][two][0]=Level2
  167.                   two++
  168.                else
  169.                   exitwhile
  170.                endif
  171.             endif
  172.          endwhile
  173.       endif
  174.    endfor
  175. ; get subdirectories in the third level
  176.    for one=0 upto 9
  177.       for two=1 upto 199
  178.          three=1
  179.          Level1=FabArray[one][0][0]
  180.          Level2=FabArray[one][two][0]
  181.          strvar3=Level2
  182.          if strcmp strvar3 $nullstr
  183.             exitfor
  184.          else
  185.             strinsert strvar3 "\" 0
  186.             strinsert strvar3 Level1 0
  187.             strinsert strvar3 "\" 0
  188.             strinsert strvar3 Leader 0
  189.             addfilename strvar3 "*.*"
  190.          endif
  191.          if findfirst strvar3 "D"                        ; findfirst
  192. Level3
  193.             Level3=$filename
  194.             strfind Level3 "."
  195.             if failure
  196.                strcmp Level3 $nullstr
  197.                if failure
  198.                   FabArray[one][two][three]=Level3
  199.                   three++
  200.                endif
  201.             endif
  202.             while findnext                               ; findnext
  203. Level3
  204.                Level3=$filename        
  205.                if strfind Level3 "."
  206.                   loopwhile
  207.                else
  208.                   strcmp Level3 $nullstr
  209.                   if failure
  210.                      FabArray[one][two][three]=Level3
  211.                      three++
  212.                   else
  213.                      exitwhile
  214.                   endif
  215.                endif
  216.             endwhile
  217.          endif
  218.       endfor
  219.    endfor
  220. ; generate file for use in fcombobox
  221.    ;fetch aspect path FileList
  222.  
  223.    addfilename FileList listfile
  224.  
  225.    fopen 0 FileList create text
  226.  
  227.    for one=0 upto 9
  228.       Level1=FabArray[one][0][0]
  229.       if strcmp Level1 $nullstr
  230.          exitfor
  231.       endif
  232.       for two=1 upto 199
  233.          Level2=FabArray[one][two][0]
  234.          if strcmp Level2 $nullstr
  235.             if two==1
  236.                fputs 0 Level1
  237.             endif
  238.             exitfor
  239.          else
  240.             for three=1 upto 19
  241.                Level3=FabArray[one][two][three]
  242.                if strcmp Level3 $nullstr
  243.                   if three==1
  244.                      line=Level1
  245.                      strcat line Level2
  246.                      fputs 0 line
  247.                   endif
  248.                   exitfor
  249.                endif
  250.                line=Level1
  251.     strcat line Level2
  252.                strcat line Level3
  253.                fputs 0 line
  254.             endfor
  255.          endif
  256.       endfor
  257.    endfor
  258.    fclose 0
  259. endproc ;GetList
  260.  
  261.  
  262.  
  263.